/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tpiServeur;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.*;
/**
 * @date 05 mai. 2011
 * @time 11:52:53
 * @author Luis.HAFNER
 */
public class VueServeur extends JFrame {
    
    private ModeleServeur modeleServeur;
    private ControleurServeur controlleurServeur;

    public VueServeur() {
        modeleServeur = new ModeleServeur();
        controlleurServeur = new ControleurServeur(this,modeleServeur);
        this.initFrame();
    }

    private void initFrame() {
        this.setLocation(50, 50);
        this.setResizable(false);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setTitle("Serveur "+this.modeleServeur.getIPLocale());
        // Panneau principal
        JPanel mainPanel = new JPanel();
        // Panneaux interne au principal
        JPanel centerPanel = initCenter();
        JPanel eastPanel = initEast();
        // Gestionnaire de placement principal
        BorderLayout bl = new BorderLayout();
        bl.setHgap(10);
        mainPanel.setBorder(BorderFactory.createEmptyBorder(20, 10, 10, 10));
        mainPanel.setLayout(bl);
        // Ajout des panneaux internes
        mainPanel.add(centerPanel,BorderLayout.CENTER);
        mainPanel.add(eastPanel,BorderLayout.EAST);
        // Ajout du panneau principal
        this.setContentPane(mainPanel);
        this.pack();
    }

    private JPanel initCenter() {
        JPanel centerPanel =new JPanel();
        centerPanel.setLayout(new BoxLayout(centerPanel,BoxLayout.Y_AXIS));
        this.texteReception = new JTextArea(10,5);
        this.texteReception.setEditable(false);
        this.texteReception.setLineWrap(true);
        JScrollPane areaScrollPane = new JScrollPane(this.texteReception);
        this.texteReception.setBorder(BorderFactory.createLineBorder(Color.blue));
        areaScrollPane.setPreferredSize(new Dimension(500,200));
        centerPanel.add(areaScrollPane);

        return centerPanel;
    }
    private JPanel initEast() {
        JPanel EastPanel =new JPanel();
        BoxLayout boxLayout = new BoxLayout(EastPanel,BoxLayout.Y_AXIS);
        EastPanel.setLayout(boxLayout);
        JLabel labelListe = new JLabel("Liste des clients");
        this.listeClients = new JList(new String[0]);
        JLabel labelPort = new JLabel("Port");
        this.champPort = new JTextField("50000");
        this.boutonDemarrer = new JButton("Démarrer");
        this.boutonDemarrer.addActionListener(this.controlleurServeur);
        this.boutonOuvrirFichier = new JButton("Fichier Log");
        this.boutonOuvrirFichier.addActionListener(this.controlleurServeur);
        this.boutonQuitter = new JButton("Quitter");
        this.boutonQuitter.addActionListener(this.controlleurServeur);
        EastPanel.add(labelListe);
        EastPanel.add(this.listeClients);
        EastPanel.add(labelPort);
        EastPanel.add(this.champPort);
        EastPanel.add(this.boutonDemarrer);
        EastPanel.add(this.boutonOuvrirFichier);
        EastPanel.add(boutonQuitter);
        return EastPanel;      
    }

    public void changerEtatBoutonDemarrer(){
        if(this.boutonDemarrer.getText()=="Démarrer")
            this.boutonDemarrer.setText("Arrêter");
        else
            this.boutonDemarrer.setText("Démarrer");
    }

    public JButton getBoutonDemarrer() {
        return boutonDemarrer;
    }

    public JButton getBoutonQuitter() {
        return boutonQuitter;
    }

    public JTextArea getReception() {
        return texteReception;
    }

    public JList getListeClients() {
        return listeClients;
    }

    public void setListeClients(JList listeClients) {
        this.listeClients = listeClients;
    }

    public JButton getBoutonOuvrirFichier() {
        return boutonOuvrirFichier;
    }

    public JTextField getChampPort() {
        return champPort;
    }

    public JTextArea getTexteReception() {
        return texteReception;
    }

    // Composants
    private JList listeClients;
    private JButton boutonDemarrer;
    private JTextArea texteReception;
    private JButton boutonQuitter;
    private JTextField champPort;
    private JButton boutonOuvrirFichier;
}
